package auto.app.controller;


import auto.app.controller.from.VariableAdd;
import auto.app.controller.from.VariableUpdate;
import auto.app.exetion.HibernateExetion;
import auto.app.exetion.MainExection;
import auto.app.model.VariableCenter;
import auto.app.service.VariableCenterService;
import auto.app.util.CommonUtil;
import auto.app.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2022-08-17
 */
@RestController
@RequestMapping("/variableCenter")
@Api(value = "变量中心",tags = "变量中心")
public class VariableCenterController {
    @Autowired
    private VariableCenterService variableCenterService;

    @PostMapping(value = "/add",name = "新增变量")
    @ApiOperation(value = "新增变量",notes = "新增变量")
    public Result<Boolean> addVariable(@Valid @RequestBody VariableAdd variableAdd) throws MainExection {
        Boolean aBoolean = variableCenterService.addVariable(variableAdd);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }

    @GetMapping(value = "/{variableId}",name = "查看变量详情")
    @ApiOperation(value = "查看变量详情",notes = "查看变量详情")
    public Result<VariableCenter> detail(@PathVariable Integer variableId ) throws MainExection {
        VariableCenter detail = variableCenterService.detail(variableId);
        return Result.getInstance(VariableCenter.class).setData(detail);
    }

    @PostMapping(value = "/update",name = "修改变量")
    @ApiOperation(value = "修改变量",notes = "修改变量")
    public Result<Boolean>  updateVariable(@Valid @RequestBody VariableUpdate variableUpdate) throws MainExection {
        Boolean aBoolean = variableCenterService.updateVariable(variableUpdate);
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }
}

